package com.woniu.supermarket.web;



import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.result.ResultResponse;
import com.woniu.supermarket.service.ISalesDetailService;
import com.woniu.supermarket.vo.SalesDetailVo;
import com.woniu.supermarket.vo.SalesDetailVoList;
import com.woniu.supermarket.vo.SalesVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("salesDetail")
@Api(value = "销售详情订单操作")
@Slf4j
public class SalesDetailController {

    @Autowired
    ISalesDetailService iSalesDetailService;

    @GetMapping("/showSalesDetail/{id}")
    @ApiOperation(value = "查询销售订单详情操作")
    public ResultResponse<List<SalesDetailVo>> showSalesDetail(@PathVariable("id")Integer id){

        ResultResponse<List<SalesDetailVo>> result = null;
        try {
            List<SalesDetailVo> salesDetailVos = iSalesDetailService.quaryAll(id);
            result = new ResultResponse<>(200,"查询销售订单详情成功",salesDetailVos);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询销售订单详情失败");
        }
        return result;
    }

/*
    @PutMapping("/resetTotal/{id}/{total}")
    @ApiOperation(value = "重置小计")
//    @ApiParam(name = "id",value = "当前详情的id")@ApiParam(name = "total",value = "当前详情的小计")
    public ResultResponse<Void> resetTotal(@PathVariable("id") Integer id,
                                           @PathVariable("total") Integer total){
        ResultResponse<Void> result = null;
        try {

            iSalesDetailService.resetTotal(id,total);
            result = new ResultResponse<>(200,"重置小计成功");
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"重置小计失败");
        }
        return result;
    }*/


    @PutMapping("/resetTotal")
    @ApiOperation(value = "重置小计")
//    @ApiParam(name = "id",value = "当前详情的id")@ApiParam(name = "total",value = "当前详情的小计")
    public ResultResponse<Void> resetTotal(@RequestBody SalesDetailVoList list){
        ResultResponse<Void> result = null;
        try {

            list.printlist();
            iSalesDetailService.resetTotalBatch(list.getTotalWithIdList());
//            iSalesDetailService.resetTotalWithList(list.getTotalWithIdList());
            result = new ResultResponse<>(200,"重置小计成功");
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"重置小计失败");
        }
        return result;
    }

}
